package com.example.demo2.controller;

import com.example.demo2.entity.Method;
import com.example.demo2.service.MethodService;
import com.google.gson.Gson;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/method")
public class MethodController {

    @Autowired
    private MethodService methodService;

    @GetMapping("/findById")
    public String findById(@Param("courseId") Integer courseId){
        Method byId = methodService.findById(courseId);
        Gson gson = new Gson();
        return gson.toJson(byId);
    }

    @GetMapping("/findByName")
    public String findByName(@Param("courseName") String courseName){
        Method byName = methodService.findByName(courseName);
        Gson gson = new Gson();
        return gson.toJson(byName);
    }

    @GetMapping("/getAllJson")
    public String getAllJson(Integer userId){
        List<Method> list = methodService.findAll(userId);
        Gson gson = new Gson();
        return gson.toJson(list);
    }

    //更新教学环节关键词
    @RequestMapping("/updateTargetById")
    public boolean updateTargetById(Integer courseId,String teacheWay){
        return methodService.updateTargetById(courseId,teacheWay);
    }
    //更新评价方式关键词
    @RequestMapping("/updateEvaluationById")
    public boolean updateEvaluationById(Integer courseId,String evaluaKeywords){
        return methodService.updateEvaluationById(courseId,evaluaKeywords);
    }
}
